package com.showde.shoppingmall.activity;

import java.util.List;

import android.view.View;
import android.widget.ListView;

import com.showde.shoppingmall.R;
import com.showde.shoppingmall.adapter.ShoppingcartModifyAdapter;
import com.showde.shoppingmall.db.ShoppingcartDBCommand;
import com.showde.shoppingmall.domain.ShoppingCart;
import com.showde.shoppingmall.utils.ActivityDispatch;

public class ShoppingcartModifyActivity extends BaseActivity {

	private ShoppingcartModifyAdapter adapter;
	private ListView listView;

	private List<String> productIdChecked;
	private List<ShoppingCart> shoppingCarts;

	private ShoppingcartDBCommand shoppingcartDBCommand;

	@Override
	public void onClick(View v) {

	}

	@SuppressWarnings("unchecked")
	@Override
	protected void initParam() {
		productIdChecked = (List<String>) intent
				.getSerializableExtra(ActivityDispatch.PRODUCT_ID_ARRAY);
		if (shoppingcartDBCommand == null) {
			shoppingcartDBCommand = new ShoppingcartDBCommand(this);
		}
	}

	@Override
	protected void initView() {
		setContentView(R.layout.activity_shoppingcart_modify);
		listView = (ListView) findViewById(R.id.lst_pro_modify);
	}

	@Override
	protected void onResume() {
		super.onResume();
		fillAdapter();
	}

	private void fillAdapter() {

		shoppingCarts = shoppingcartDBCommand
				.queryShoppingcartByProductIdArray(productIdChecked);
		if (shoppingCarts == null || shoppingCarts.size() == 0) {
			return;
		}
		adapter = (ShoppingcartModifyAdapter) listView.getAdapter();
		if (adapter == null) {
			adapter = new ShoppingcartModifyAdapter(this, shoppingCarts);
			listView.setAdapter(adapter);
		} else {
			adapter.resetData(shoppingCarts);
		}
		adapter.notifyDataSetChanged();
	}

}
